package model.effect;

import utilities.Archive;
import model.entity.BasicEntity;
import model.handler.MovementHandler;
import model.map.Direction;
import model.map.HexLocationProjection;
import model.map.Location;
import model.map.LocationProjection;

/**
 * This class represents an effect that will push an entity in a specified direction at a specified rate.
 */
public class FlowEffect extends Effect
{

	Direction direction;
	double rate;
	
	/* --------------------------------------------------------------------------------
	 * Constructors
	   -------------------------------------------------------------------------------- */
	
	/**
	 * @param name The name of this model
	 * @param direction The direction that the effect will push the entity
	 * @param rate The rate at which the effect will push the entity.
	 */
	public FlowEffect(String name, Direction direction, double rate)
	{
		super(name);
		this.direction = direction;
		this.rate = rate;
	}

	public FlowEffect(){}
	
	/* --------------------------------------------------------------------------------
	 * Getters and Setters
	   -------------------------------------------------------------------------------- */

	public Direction getDirection()
	{
		return direction;
	}

	public double getRate()
	{
		return rate;
	}

	/* --------------------------------------------------------------------------------
	 * Class methods
	   -------------------------------------------------------------------------------- */
	
	@Override
	public void doEffect(BasicEntity ent)
	{
		// TODO Auto-generated method stub

		LocationProjection moveLogic;
		Location pLocation;
		Location curLocation;

		moveLogic	= new HexLocationProjection();
		curLocation = ent.getLocation();
		pLocation = moveLogic.projectLocation(curLocation, direction);

		MovementHandler mh = MovementHandler.getInstance();
		mh.moveEntity(ent, direction);
		//ent.setLocation(pLocation);
	}

	@Override
	public String toString()
	{
		return super.toString() + "FlowEffect [direction=" + direction + ", rate=" + rate + "]";
	}
	
	public Archive save() {
		Archive archive = super.save();
		
		// can't save direction, can't save enums
		
//		archive.putAttribute("rate", Double.toString(this.rate));
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
//		this.rate = Double.parseDouble(archive.getAttribute("rate"));
	}
	
}
